#!/bin/bash

#
# This script outputs the number of days since 1/1/1970
#
seconds_gnu_epoch=`date +'%s'`

# This is the equation that works for the Gregorian calendar for years from
# 1582 through 9999.  If you need to calculate something else, you'll need 
# a new equation.
epoch_days=$(((1969*365)+(1969/4)-(1969/100)+(1969/400)+(14*306001/10000)+1))

day=`date +'%d'`
month=`date +'%m' | sed 's/0*//'`
year=`date +'%Y'`

if [ $month -gt 2 ]
then
  month=$((month+1))
else
  month=$((month+13))
  year=$((year-1))
fi

today_days=$(((year*365)+(year/4)-(year/100)+(year/400)+(month*306001/10000)+day))
days_since_epoch=$((today_days-epoch_days))
echo $days_since_epoch
